package com.jinly.ryder.config;

import com.jinly.ryder.log.service.LogInstallService;
import com.jinly.ryder.manage.service.model.AppInfo;
import com.jinly.ryder.manage.service.model.AppInfoSaveEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

@Slf4j
@Configuration
public class EventConfig {

    @Autowired
    private LogInstallService logInstallService;

    @EventListener
    public void handleAppInfoSaveEvent(AppInfoSaveEvent appInfoSaveEvent) {
        log.info("监听到AppInfoSaveEvent事件，消息为：{}", appInfoSaveEvent);
        AppInfo appInfo = (AppInfo) appInfoSaveEvent.getSource();
        logInstallService.install(appInfo.getAppName());
    }
}
